package com.ghca.myinfo3.system.repository;

import com.ghca.myinfo3.system.entity.Permission;
import com.ghca.myinfo3.system.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2016/12/18.
 */
@Repository
public interface PermissionRepository extends JpaRepository<Permission, Long> {

    List<Permission> findByParentId(Long parentId);

    List<Permission> findByIdOrParentId(Long id, Long parentId);

    @Query("from Permission p where ?1 MEMBER OF p.roles and (p.parent is null)")
    List<Permission> findByRole(Role role);



}
